package cn.dengta.webapp.risk.config;

import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 数美风控模块配置
 */
@Configuration
public class RiskConfiguration {

	public static final String RISK_TASK_EXECUTOR_BEAN_NAME = "riskTaskExecutor";

	@Bean(name = RISK_TASK_EXECUTOR_BEAN_NAME)
	@Lazy
	public TaskExecutor riskTaskExecutor() {
		ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
		pool.setThreadNamePrefix("Risk-Pool-");
		pool.setCorePoolSize(45);
		pool.setMaxPoolSize(45);
		pool.setQueueCapacity(450);
		pool.setKeepAliveSeconds(300);
		pool.setWaitForTasksToCompleteOnShutdown(true);
		pool.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
		return pool;
	}

}
